package collection;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;
import java.util.stream.Collectors;

public class StreamApiDemo1 {
    public static void main(String[] args) {
        Random rand = new Random();
        List<Integer> list = new ArrayList<>();
        Scanner scanner = new Scanner(System.in);
        System.out.println("输入你所需要的数组长度：");
        int len = scanner.nextInt();
        for (int i = 0; i < len; i++) {
            list.add(rand.nextInt(100));
        }
        System.out.println(list);
        List<Integer> list1 =  list.stream()
                .map(a->a*3)
                .collect(Collectors.toList());
        System.out.println(list1);

        List<Integer> list2 = list.stream().filter(a->a%2==0).collect(Collectors.toList());
        System.out.println(list2);//筛选偶数

        //降序
        List<Integer> list4 = list.stream().sorted((e1,e2)->e2-e1).collect(Collectors.toList());
        System.out.println(list4);

        //对集合每个元素扩大3倍并获取其中所有的偶数并降序排列
        List<Integer> list5 = list.stream()
                .map(e->e*3)
                .filter(e->e%2==0)
                .sorted((e1,e2)->e2-e1)
                .collect(Collectors.toList());
        System.out.println(list5);
    }
}
